$(document).ready(function() {

	var thumbnails	= $("ul.processingThumbnails li a");
	thumbnails.each(function(k,e){
		$(e).click(function(event) {
			event.preventDefault();
			event.stopPropagation();
			var title = $(this).children("img:first").attr("title");
			var desc = $("p.processingDescription");
			desc.html(title);
			
			$.get($(this).attr("href"), function(source) {
				var source = source.replace(/size\(.*?,.*?\);/, "size\(" + ProcessingAS.p.width +"," + ProcessingAS.p.height + "\);");

				var images = [];
				var regex = /loadImage\(\"(.*)\"\);/g;
				var matches = source.match(regex);
				if (matches) {
					for (var i = 0; i < matches.length; i++) {
						var name = matches[i].replace(/loadImage\(\"(.*)\"\);/g, "$1");
						var path = new RegExp(name);
						source = source.replace(path, PImages[name]);
						images.push([PImages[name], PImages[name]]);
					}
				}
				ProcessingAS.element.run(source,images);
			});
			return false;
		})
	});

 });
